﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeGame.LuaLibary
{
    static class luaLib_luahelp
    {
        [LuaHelp("Lists all luahelp entrys, kinda useless unless you have a massive screen")]
        public static void listAll()
        {
            Singletons.Console.Print("All LuaHelp: ", Singletons.NormalText);
            foreach (KeyValuePair<string, string> item in Singletons.LuaHelp)
            {
                Singletons.Console.Print(item.Key.PadRight(Singletons.MaxLuaHelpLength) + " : " + item.Value, Singletons.NormalText);
            }
        }

        [LuaHelp("Exports the entire database")]
        public static string exportDatabase()
        {
            string str = "";
            foreach (KeyValuePair<string, string> item in Singletons.LuaHelp)
            {
                str += item.Key.PadRight(Singletons.MaxLuaHelpLength) + " : " + item.Value + Environment.NewLine;
            }
            return str;
        }

        [LuaHelp("Lists a single page of the database, much more useful")]
        public static void list(int page)
        {
            Singletons.Console.Print("Lua Help Page: " + page.ToString(), Singletons.NormalText);

            if (page > (Singletons.LuaHelp.Count / 15))
            {
                Singletons.Console.Print("Page Extends beyond total length", Singletons.ErrorText);
            }
            else
            {

            }
        }

        [LuaHelp("Adds a item to the database via lua, good for lua libarys")]
        public static void add(string name, string description)
        {
            if (!Singletons.LuaHelp.ContainsKey(name))
            {
                Singletons.LuaHelp.Add(name, description);
            }
        }

        [LuaHelp("Searchs the database for a term")]
        public static void search(string term)
        {
            Singletons.Console.Print("LuaHelp Search for: " + term, Singletons.NormalText);

            Dictionary<string, string> items = Singletons.LuaHelp;

            foreach (KeyValuePair<string, string> item in items)
            {
                if (item.Key.Contains(term))
                {
                    Singletons.Console.Print(item.Key.PadRight(Singletons.MaxLuaHelpLength) + " : " + item.Value, Singletons.NormalText);
                }
            }
        }
    }
}
